﻿// -----------------------------------------------------------------------
// <copyright file="Task.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace HashMaster.Lib
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Serialization;
    /// <summary>
    /// 任务信息
    /// </summary>
    [DataContract]
    public class Task
    {
        /// <summary>
        /// 任务的优先级
        /// </summary>
        [DataMember]
        public int Priority { get; set; }

        /// <summary>
        /// 任务的imei
        /// </summary>
        [DataMember]
        public string Imei { get; set; }

        /// <summary>
        /// 任务的sha
        /// </summary>
        [DataMember]
        public string Sha { get; set; }

        /// <summary>
        /// 分块宽度
        /// </summary>
        [DataMember]
        public int SliceWidth { get; set; }

        /// <summary>
        /// 运算结果
        /// </summary>
        [DataMember]
        public string Result { get; set; }

        /// <summary>
        /// 该任务的所有子任务
        /// </summary>
        [DataMember]
        public List<Job> Jobs { get; set; }

        ///// <summary>
        ///// 任务状态
        ///// </summary>
        //[DataMember]
        //public EnumStatus Status { get; set; }

        [DataMember]
        public int StatusId { get; set; }

        /// <summary>
        /// 任务的备注
        /// </summary>
        [DataMember]
        public string Memo { get; set; }
        
        /// <summary>
        /// COD导出标记
        /// </summary>
        [DataMember]
        public bool Extracted { get; set; }

        public Task() 
        {
            //Jobs = new List<Job>();
            Result = string.Empty;
            //Status = EnumStatus.Pending;
            
        }

        /// <summary>
        /// 
        /// </summary>
        [DataMember]
        public string Progress { get; set; }
        /// <summary>
        /// 任务进度只读，通过子任务的进度计算
        /// 该属性即时运算 不用序列化 
        /// </summary>
        //[IgnoreDataMember]
        //public int Progress
        //{
        //    get
        //    {
        //        ///计算所有job的平均进度
        //        double jobCount = 0;
        //        double jobTotalProgress = 0;
        //        foreach (var j in Jobs)
        //        {
        //            jobCount++;
        //            jobTotalProgress += j.Progress;
        //        }
        //        return Convert.ToInt16(Math.Round(jobTotalProgress / jobCount, 0));
        //    }
        //}

    }


}
